package com.vf.admin.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtils {
    public static String formatDateTime(long mss) {
        String DateTimes = null;
        long days = mss / (60 * 60 * 24);
        long hours = (mss % (60 * 60 * 24)) / (60 * 60);
        long minutes = (mss % (60 * 60)) / 60;
        long seconds = mss % 60;
        if (days > 0) {
            DateTimes = days + "天" + hours + "小时" + minutes + "分钟"
                    + seconds + "秒";
        } else if (hours > 0) {
            DateTimes = hours + "小时" + minutes + "分钟"
                    + seconds + "秒";
        } else if (minutes > 0) {
            DateTimes = minutes + "分钟"
                    + seconds + "秒";
        } else {
            DateTimes = seconds + "秒";
        }

        return DateTimes;
    }

    /**
     * 倒计时
     *
     * @param endTime
     * @return
     */
    public static String daojishi(Date endTime) {
        //按照传入的格式生成一个simpledateformate对象
        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        long nd = 1000 * 24 * 60 * 60;//一天的毫秒数
        long nh = 1000 * 60 * 60;//一小时的毫秒数
        long nm = 1000 * 60;//一分钟的毫秒数
        long ns = 1000;//一秒钟的毫秒数long diff;
        //获得两个时间的毫秒时间差异
        long diff;
        //diff = sd.parse(endTime).getTime() - sd.parse(startTime).getTime();
        diff = endTime.getTime() - System.currentTimeMillis();
        String day = diff / nd + "";//计算差多少天
        String hour = diff % nd / nh + "";//计算差多少小时
        String min = diff % nd % nh / nm + "";//计算差多少分钟
        //String sec = diff % nd % nh % nm / ns +"";//计算差多少秒//输出结果
        if (Integer.valueOf(day) > 0) {
            return day + " 天";
        } else {
            if (Integer.valueOf(hour) > 0) {
                return hour + " 时";
            } else {
                if (Integer.valueOf(min) > 0) {
                    return min + " 分";
                } else {
                    return "";
                }
            }
        }
    }

    public static String getNow(){
        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentTime = sdf.format(now);
        return currentTime;
    }

    public static boolean afterNow(Date sourceDate){
        boolean flag = false;
        try {
            Date nowDate = new Date();
            flag = sourceDate.after(nowDate);
        }catch (Exception e){
        }
        return flag;
    }

    public static void main(String[] args) {
        String name="a.phone.jpg";
        String suffix = name.substring(name.lastIndexOf("."));
        System.out.println(suffix);

    }
}
